package http.java.io;

import http.java.io.client.HttpClient;
import http.java.io.client.RequestContext;
import http.java.io.client.ResponseContext;

import java.net.URL;

/**
 * @author Jonatan Ivanov
 */
public class Main {

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        ResponseContext rsContext = new ResponseContext();
        RequestContext rqContext = new RequestContext(new URL("http://httpbin.org/ip"));
        HttpClient.invoke(rqContext, rsContext);

        System.out.println("Headers:");
        System.out.println(rsContext.getHeadersAsString());

        System.out.println("Response:");
        byte[] responseBytes = rsContext.getResponseBytes();
        String response = (responseBytes != null) ? new String(responseBytes) : "null";
        System.out.println(response);
    }
}
